import { useEffect } from 'react'
import { isFunction } from '../tool-kits/is-valid'
import { IS_DEV } from '../tool-kits/get-process-env'

interface UseMount {
  (fn: () => void): void
}

export const useMount: UseMount = function (fn) {
  if (IS_DEV && !isFunction(fn)) {
    console.error('useMount: parameter `fn` expected to be a function, but got "'.concat(typeof fn, '".'))
  }
  useEffect(() => {
    fn?.()
  }, [])
}
